package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Business;
import cn.wolfcode.mapper.BusinessMapper;
import cn.wolfcode.qo.BusinessQueryObject;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IBusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Random;

@Service
@Transactional
public class BusinessServiceImpl implements IBusinessService {
    private BusinessMapper businessMapper ;

    @Autowired
    public void setBusinessMapper(BusinessMapper businessMapper) {
        this.businessMapper = businessMapper;
    }

    @Override
    public void insert(Business business) {
        businessMapper.insert(business);
    }

    @Override
    public void delete(Long id) {
        businessMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Business business) {
        businessMapper.updateByPrimaryKey(business);
    }

    @Override
    public Business selectById(Long id) {
        Business business = businessMapper.selectByPrimaryKey(id);
        return business ;
    }

    @Override
    public List<Business> selectAll() {
        List<Business> businesss = businessMapper.selectAll();
        return businesss ;
    }

    @Override
    public PageInfo<Business> query(BusinessQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"open_date desc");
        List<Business> businesss = businessMapper.queryAll(qo);
        return new PageInfo<>(businesss);
    }

    @Override
    public Business selectByMain() {
        return businessMapper.selectByMain();
    }

    
}
